package com.brush.brushcommon.dto;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.HashMap;

@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    private boolean success;

    private Integer code;

    private String msg;

    private Object data;

    private Object pageParams;

    public static  Result success(){
        return new Result(true,200,"success",null,null);
    }

    public static Result success(Object data) {
        return new Result(true,200,"success",data,null);
    }
    public static Result fail(Integer code, String msg) {
        return new Result(false,code,msg,null,null);
    }
    public static Result fail(String msg) {
        return new Result(false,500,msg,null,null);
    }
    public static Result fail(){
        return new Result(false,9999,"error",null,null);
    }

    public static Result custom(boolean success,Integer code,String msg,Object data) {
        return new Result(success,code,msg,data,null);
    }

    public static Result successPage(Page<?> page){
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",page.getTotal());
        map.put("pageNum",page.getCurrent());
        map.put("pageSize",page.getSize());
        return new Result(true,200,"success",page.getRecords(),map);
    }

}
